package com.ydw;

import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

/**
 * @author Yangdw
 * @date 2025-08-31
 * @description:
 */
public class ProducerSelfDefined {

    public static void main(String[] args) throws MQClientException {
        DefaultMQProducer producer = new DefaultMQProducer("test-producer-group",
                true,
                "CUSTOM_GLOBAL_TRACE_TOPIC");
        producer.setNamesrvAddr("127.0.0.1:9876");
        JSONObject data = new JSONObject();
        data.put("message","你好好");
        producer.start();
        try {
            {
                Message msg = new Message("test-topic-TRACE",
                        "TagA",
                        "OrderID188",
                        data.toJSONString().getBytes(RemotingHelper.DEFAULT_CHARSET));
                msg.setKeys("CUSTOMER_TK");

                SendResult sendResult = producer.send(msg);
                System.out.printf("%s%n", sendResult);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
